package section6_8;

/**
 * Created by Hyman on 2017/6/15.
 *
 * 使用原子变量
 */
public class Main {

    public static void main(String[] args) {

        Account account = new Account();
        account.setBalance(1000);

        Company company = new Company(account);
        Thread companyThread = new Thread(company);

        Bank bank = new Bank(account);
        Thread bankThread = new Thread(bank);

        // 输出帐户对象最初的信息
        System.out.printf("Account : Initial Balance: %d\n", account.getBalance());

        // 启动线程
        companyThread.start();
        bankThread.start();

        try {
            // 等待线程完成
            companyThread.join();
            bankThread.join();
            // 输出余额
            System.out.printf("Account : Final Balance: %d\n", account.getBalance());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
